package com.cn.jinl.controller;

import com.cn.jinl.api.ITerminalAccessService;
import com.cn.jinl.domain.TerminalAccess;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created On : 2024/1/10.
 * <p>
 * Author : Huiyan
 * <p>
 * Description: 扩展应用----终端许可
 */
@Controller
@RequestMapping("/terminal")
public class TerminalAccessController {

    @Autowired
    private ITerminalAccessService terminalAccessService;


    /**
     * @author : Huiyan feng
     * @date   : 2024/1/10
     * @param  : [queryForm]
     * @return : com.cn.jinl.utils.JsonResponse<java.util.List<com.cn.jinl.domain.TerminalAccess>>
     * @description : 获取终端信息 列表
     */
    @RequestMapping("/getTerminalList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<TerminalAccess>> getTerminalList(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<List<TerminalAccess>> response = new JsonResponse<>();
        List<TerminalAccess> list = terminalAccessService.getTerminalList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return response;
    }

    /**
     * @author : Huiyan feng
     * @date   : 2024/1/10
     * @param  : [terminalAccesses]
     * @return : com.cn.jinl.utils.JsonResponse<java.lang.String>
     * @description : 批量增加终端信息
     */
    @RequestMapping("/addTerminalList/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addTerminalList(@RequestBody List<TerminalAccess> terminalAccesses,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = terminalAccessService.addTerminalList(terminalAccesses);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/updateTerminal/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateTerminal(@RequestBody TerminalAccess terminalAccess,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = terminalAccessService.updateTerminal(terminalAccess);
        return CommonUtil.getResponseData(response,result);
    }


    /**
     * @author : Huiyan feng
     * @date   : 2024/1/10
     * @param  : [queryForm, frontToken]
     * @return : com.cn.jinl.utils.JsonResponse<java.lang.String>
     * @description : 删除终端
     */
    @RequestMapping("/deleteTerminalInfo/{frontToken}")
    @ResponseBody
    public JsonResponse<String> deleteTerminalInfo(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = terminalAccessService.deleteTerminalInfo(queryForm);
        return CommonUtil.getResponseData(response,result);
    }

    /**
     * @author : Huiyan feng
     * @date   : 2024/1/10
     * @param  : [queryForm, frontToken]
     * @return : com.cn.jinl.utils.JsonResponse<java.util.Map<java.lang.String,java.lang.Object>>
     * @description : 列表  合计  已授权  未授权 等页面数据全用此方法调用
     */
    @ResponseBody
    @RequestMapping("/getTerminalAllInfo/{frontToken}")
    public JsonResponse<Map<String,Object>> getTerminalAllInfo(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<Map<String,Object>> response = new JsonResponse<>();
        Map<String,Object> result = terminalAccessService.getTerminalAllInfo(queryForm);
        response.setResult(result);
        response.setSuccess(null == result ? false : true);
        response.setMessage(null == result ? "获取数据异常" : "");
        return response;
    }





}
